package it.tukano.lang;

import it.tukano.io.FileExt;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;

public class SystemExt {

    private static final Object LOCK = new Object();
    private static Icon FOLDER_ICON;
    
    static {
        synchronized (LOCK) {
            try {
                FOLDER_ICON = FileSystemView.getFileSystemView().getSystemIcon(new File(System.getProperty("user.home")));
            } catch(Throwable t) {
                Logger.getLogger(SystemExt.class.getName()).log(Level.INFO, "cannot load system folder icon");
            }
        }
    }
    
    public static Icon getSystemFolderIcon() {
        synchronized (LOCK) {
            return FOLDER_ICON;
        }
    }
    
    public static Icon findFileIcon(String extension) {
        if(!extension.startsWith(".")) {
            extension = "." + extension;
        }
        FileExt file = FileExt.createTempFile("txt");
        Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file.getFile());
        file.delete();
        return icon;
    }
}
